package com.qiankan.qmsj.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import com.qiankan.qmsj.R;


/**
 * Created by Administrator on 2016/7/29.
 */
public class LoadDialog extends Dialog {
    private TextView textView;//内容
    private ImageView loadingView;
    private Animation animation;
    private Handler handler = new Handler(Looper.getMainLooper());

    public LoadDialog(Context context) {
        super(context, R.style.BankDialog);
        View rootView = LayoutInflater.from(context).inflate(R.layout.loading_dialog, null);
        textView = (TextView) rootView.findViewById(R.id.loading_text);
        loadingView = (ImageView) rootView.findViewById(R.id.iv_img);
        animation = AnimationUtils.loadAnimation(context, R.anim.xuanzhuan);
        animation.setInterpolator(new LinearInterpolator());
        setContentView(rootView);
    }

    /*public synchronized static LoadDialog getInstance(Context context) {
        if (mInstance == null || mContext != context) {
            mInstance = new LoadDialog(context);
        }
        return mInstance;
    }*/

    public void setLoadingText(String text) {
        textView.setText(text);
    }

    @Override
    public void show() {
        setCanceledOnTouchOutside(false);
        loadingView.startAnimation(animation);
        super.show();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}